package cn.newtouch.pet.service.impl;

import cn.newtouch.basic.service.impl.BaseServiceImpl;
import cn.newtouch.pet.domain.Pet;
import cn.newtouch.pet.domain.PetDetail;
import cn.newtouch.pet.mapper.PetMapper;
import cn.newtouch.pet.mapper.PetDetailMapper;
import cn.newtouch.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

// @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
@Service
public class PetServiceImpl extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetMapper petMapper;

    @Autowired
    private PetDetailMapper petDetailMapper;

    @Override
    public void save(Pet pet) {
        //保存pet表 返回自增主键
        petMapper.save(pet);
        //保存pet_detail表
        PetDetail petDetail = pet.getPetDetail();
        petDetail.setPet_id(pet.getId());
        petDetailMapper.save(petDetail);
    }

    @Override
    public void update(Pet pet) {
        //修改pet
        petMapper.update(pet);
        //修改pet_detail
        petDetailMapper.update(pet.getPetDetail());
    }

    @Override
    public void remove(Long id) {
       //先删除pet_detail

        petDetailMapper.remove(id);

        //再删除Pet
        petMapper.remove(id);



    }

    @Override
    public void onSale(List<Long> ids) {
        //先审核

        //再改状态 上架
        Date date = new Date();
        petMapper.onSale(ids,date);
    }

    @Override
    public void offSale(List<Long> ids) {
        //改状态 下架
        Date date = new Date();
        petMapper.offSale(ids,date);



    }
}
